package thread;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-25 17:48
 **/
public class MyThread extends Thread {
    private static int i = 100;
    private static Object object = new Object();

    @Override
    public void run() {

        while (true) {
            if (!synchronizedMethod()) {
                break;
            }

            // synchronized (MyThread.class) {
            //     if (i <= 0) {
            //         break;
            //     } else {
            //         System.out.println(Thread.currentThread().getName() + "消费了第: " + i + " 张票");
            //         i--;
            //     }
            // }
        }
    }

    private static synchronized boolean synchronizedMethod() {
        if (i <= 0) {
            return false
                    ;
        } else {
            System.out.println(Thread.currentThread().getName() + "消费了第: " + i + " 张票");
            i--;
            return true;
        }
    }
}
